// 页面路由文件
import {createRouter, createWebHistory} from 'vue-router'

// 自定义组件
const Home = () => import( '../views/Home/Home.vue')// 首页
const Category = () => import( '../views/category/Category.vue')// 分类
const Detail = () => import( '../views/detail/Detail.vue')// 详情
const shopCart = () => import( '../views/shopcart/shopCart.vue') // 购物车组件
const Profile = () => import('../views/profile/Profile.vue') // 个人中心组件
const Register = () => import( "@/views/profile/register/Register") // 注册组件组件
const Login = ()=> import('@/views/profile/login/Login')
const routes = [
	{
		path: '/', // 重定向
		name: 'Default',
		component: Home, // 使用的组件
		meta: { // 设置html的meta属性
			title: '叮当图书商城'
		}
	},
	{
		path: '/home',
		name: 'Home',
		component: Home,
		meta: {
			title: '叮当图书商城'
		}
	},
	{
		path: '/detail',
		name: 'Detail',
		component: Detail,
		meta: {
			title: '叮当图书商城-商品详情'
		}
	},
	{
		path: '/category',
		name: 'Category',
		component: Category,
		meta: {
			title: '叮当图书商城-分类页面'
		}
	},
	{
		path: '/profile',
		name: 'Profile',
		component: Profile,
		meta: {
			title: '叮当图书商城-个人中心'
		}
	},
	{
		path: '/register',
		name: 'Register',
		component: Register,
		meta: {
			title: '叮当图书商城-用户注册'
		}
	},
	{
		path: '/login',
		name: 'Login',
		component: Login,
		meta: {
			title: '叮当图书商城-用户登录'
		}
	},
	{
		path: '/shopcart',
		name: 'shopCart',
		component: shopCart,
		meta: {
			title: '叮当图书商城-购物车'
		}
	},
	
]

const router = createRouter({
	history: createWebHistory(process.env.BASE_URL),
	routes
})
// 全局导航守卫
router.beforeEach((to, from, next) => {
//如果没有登录,在这里跳转到登录
	next();
	document.title = to.meta.title //更改跳转之后的title标签内容
})
export default router
